from client_resource.base_resource import BaseResource
import pymysql


class MysqlClient(BaseResource):
    def __init__(self, init_config):
        super().__init__(init_config)

    def create_conn(self, database):
        cnn = pymysql.connect(host=self.config["host"],
                              user=self.config["user"],
                              password=self.config["password"],
                              database=database,
                              charset="utf-8")
        return cnn

    def get_user_by_id(self, user_id):
        database = "service_recommend"
        conn = self.create_conn(database)
        cursor = conn.cursor()

        sql = """
        select * from user 
        where user_id = %s 
        """

        res = cursor.execute(sql, [user_id])
        cursor.close()
        print(res)



